<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.1.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"liukairui.me","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.10.1","exturl":false,"sidebar":{"position":"left","display":"hide","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":true,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null,"activeClass":"valine"},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="HTML&amp;CSS入门笔记,主讲:尚硅谷李立超,视频来自B站:BV1XJ411X7Ud">
<meta property="og:type" content="article">
<meta property="og:title" content="HTML&amp;CSS学习笔记">
<meta property="og:url" content="http://liukairui.me/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">
<meta property="og:site_name" content="LiuKairui Website">
<meta property="og:description" content="HTML&amp;CSS入门笔记,主讲:尚硅谷李立超,视频来自B站:BV1XJ411X7Ud">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-10-30T16:00:19.000Z">
<meta property="article:modified_time" content="2021-10-18T06:44:13.570Z">
<meta property="article:author" content="Liu Kairui">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="笔记">
<meta property="article:tag" content="CSS">
<meta property="article:tag" content="HTML">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://liukairui.me/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://liukairui.me/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/","path":"article/HTML&CSS学习笔记/","title":"HTML&CSS学习笔记"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>HTML&CSS学习笔记 | LiuKairui Website</title>
  

  <script src="/js/third-party/analytics/baidu-analytics.js"></script>
  <script async src="https://hm.baidu.com/hm.js?ea07bceb8f5fa721da2ebf01833faa32"></script>



<div class="nindexBK">
<div class="nindexBKC"></div>
<div class="nindex">
  <h1>Hey👋</h1>
  <p style="font-weight: 500; font-size: 2.2em">欢迎访问Liu Kairui的个人站.</p>
  <p>
      我是一个来自重庆的在校大学生, 偏爱于前端技术<!--与OS设计-->, 偶尔使用 JS / Go 进行轻量项目开发, 欢迎访问我的
      <a href="https://github.com/KairuiLiu" target="_blank"><i class="fab fa-github-alt"></i> GitHub</a> .
  </p>
  <p>
      这个网站主要用来存储学习 / 瞎搞的笔记, 同时提供了邮件、图床等服务. 对于一些自认为有趣的<a href="javascript:;" id="myProj">项目</a>, 我也会将项目介绍, 文档, 甚至是设计指南发布在这里.
  </p>
  <ul>
    <li><p><a href="/artrank/" target="_blank">ArtRank</a>: 基于Node.JS的PageRank文献管理推荐系统</p></li>
    <li><p><a href="/gooj/" target="_blank">GoOJ</a>: 基于Golang的高校在线评测系统</p></li>
    <li><p><a href="/projects/" target="_blank">更多 <i class="fas fa-angle-right"></i></a></p></li>

  </ul>
  <p>
      可以在这些平台找到我: 
      <a href="https://www.zhihu.com/people/liu-kai-rui-18" target="_blank">知乎</a>,
      <a href="https://space.bilibili.com/33238144" target="_blank">bilibili</a>
      和
      <a href="https://www.coolapk.com/u/805314?from=qr" target="_blank">酷安</a>.
  </p>

  <p>
      下滑即可进入博客 <i class="fas fa-arrow-down"></i>
  </p>
</div>
</div>  

 
<script>
  var OriginTitile = document.title;
  var titleTime;
  document.addEventListener("visibilitychange", function() {
    if (document.hidden) {
      document.title = "谢谢离开 | " + OriginTitile;
      clearTimeout(titleTime);
    } else {
      document.title = "欢迎归来 | " + OriginTitile;
      titleTime = setTimeout(function() {
        document.title = OriginTitile;
      }, 2000);
    }
  });
</script>


<script>
  function checkIndex(){
    let nindexItems = [[".nindexBK","display","block","none"],[".headband","display","none","block"],["div.toggle.sidebar-toggle","visibility","hidden","visible"]]; // ,["button.darkmode-toggle","visibility","hidden","visible"]];
    let isIndex = new RegExp("^(\/){0,1}(index){0,1}(\.html){0,1}(/)*$").test(location.pathname);
    let backCanvas = document.querySelector(".nindexBK");
    nindexItems.dispShift = function (stat){this.forEach((e) => {try{document.querySelector(e[0]).style[e[1]]=e[2+stat];}catch{}})}
    if(isIndex){
      nindexItems.dispShift(0);
      window.onscroll=function(){
        if(document.documentElement.scrollTop>backCanvas.offsetHeight*1.05){
          nindexItems.dispShift(1);window.onscroll=null;
        }
      }
      document.querySelector("#myProj").onclick=()=>{
        let projlist = document.querySelector(".nindex>ul");
        projlist.className.indexOf("ulactive")==-1?projlist.classList.add("ulactive"):projlist.classList.remove("ulactive")
      }
    }else nindexItems.dispShift(1);
  }
  checkIndex();
</script>

<!--<script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>-->

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="LiuKairui Website" type="application/atom+xml">
<style>.darkmode--activated{--body-bg-color:#282828;--content-bg-color:#333;--card-bg-color:#555;--text-color:#ccc;--blockquote-color:#bbb;--link-color:#ccc;--link-hover-color:#eee;--brand-color:#ddd;--brand-hover-color:#ddd;--table-row-odd-bg-color:#282828;--table-row-hover-bg-color:#363636;--menu-item-bg-color:#555;--btn-default-bg:#222;--btn-default-color:#ccc;--btn-default-border-color:#555;--btn-default-hover-bg:#666;--btn-default-hover-color:#ccc;--btn-default-hover-border-color:#666;--highlight-background:#282b2e;--highlight-foreground:#a9b7c6;--highlight-gutter-background:#34393d;--highlight-gutter-foreground:#9ca9b6}.darkmode--activated img{opacity:.75}.darkmode--activated img:hover{opacity:.9}.darkmode--activated code{color:#69dbdc;background:0 0}button.darkmode-toggle{z-index:9999}.darkmode-ignore,img{display:flex!important}</style></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">LiuKairui Website</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">要有信仰</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fas fa-hashtag fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-收藏夹"><a href="/favorites/" rel="section"><i class="fab fa-gratipay fa-fw"></i>收藏夹</a></li>
        <li class="menu-item menu-item-留言板"><a href="/messageBoard/" rel="section"><i class="fab fa-facebook-messenger fa-fw"></i>留言板</a></li>
        <li class="menu-item menu-item-项目"><a href="/projects/" rel="section"><i class="fa fa-satellite fa-fw"></i>项目</a></li>
        <li class="menu-item menu-item-图床"><a href="http://img.liukairui.me/" rel="noopener" target="_blank"><i class="fa fa-bed fa-fw"></i>图床</a></li>
        <li class="menu-item menu-item-云ide"><a href="http://vsc.liukairui.me/" rel="noopener" target="_blank"><i class="fas fa-code fa-fw"></i>云IDE</a></li>
        <li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
        <li class="menu-item menu-item-邮箱"><a href="http://mail.liukairui.me/mail" rel="noopener" target="_blank"><i class="fas fa-envelope-open-text fa-fw"></i>邮箱</a></li>
        <li class="menu-item menu-item-rss"><a href="/atom.xml" rel="section"><i class="fa fa-rss fa-fw"></i>RSS</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#html%E5%9F%BA%E7%A1%80"><span class="nav-number">1.</span> <span class="nav-text">1. HTML基础</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BD%91%E9%A1%B5%E7%9A%84%E7%BB%93%E6%9E%84"><span class="nav-number">1.1.</span> <span class="nav-text">1.1 网页的结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#html%E4%B8%AD%E7%9A%84%E5%AE%9E%E4%BD%93"><span class="nav-number">1.2.</span> <span class="nav-text">1.2 HTML中的&quot;实体&quot;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#meta-%E6%A0%87%E7%AD%BE"><span class="nav-number">1.3.</span> <span class="nav-text">1.3 meta 标签</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AF%AD%E4%B9%89%E5%8C%96%E6%A0%87%E7%AD%BE"><span class="nav-number">2.</span> <span class="nav-text">1.4 语义化标签</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%97%E8%A1%A8"><span class="nav-number">3.</span> <span class="nav-text">1.7 列表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%B6%85%E9%93%BE%E6%8E%A5"><span class="nav-number">4.</span> <span class="nav-text">1.8 超链接</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9B%BE"><span class="nav-number">5.</span> <span class="nav-text">1.9 图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%86%85%E8%81%94%E6%A1%86%E6%9E%B6"><span class="nav-number">6.</span> <span class="nav-text">1.10 内联框架</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9F%B3%E8%A7%86%E9%A2%91"><span class="nav-number">7.</span> <span class="nav-text">1.11 音视频</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#css%E7%AE%80%E4%BB%8B"><span class="nav-number">8.</span> <span class="nav-text">2.1 CSS简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#css%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95"><span class="nav-number">9.</span> <span class="nav-text">2.2 CSS基本语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#css-%E9%80%89%E6%8B%A9%E5%99%A8%E5%9F%BA%E7%A1%80"><span class="nav-number">10.</span> <span class="nav-text">2.3 CSS 选择器基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#css%E7%9A%84%E5%A4%8D%E5%90%88%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">11.</span> <span class="nav-text">2.4 CSS的复合选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B3%E7%B3%BB%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">12.</span> <span class="nav-text">2.5 关系选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B1%9E%E6%80%A7%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">13.</span> <span class="nav-text">2.6 属性选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BC%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">14.</span> <span class="nav-text">2.7 伪类选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a%E5%85%83%E7%B4%A0%E7%9A%84%E4%BC%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">15.</span> <span class="nav-text">2.8 a元素的伪类选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BC%AA%E5%85%83%E7%B4%A0%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">16.</span> <span class="nav-text">2.9 伪元素选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A0%B7%E5%BC%8F%E7%9A%84%E7%BB%A7%E6%89%BF"><span class="nav-number">17.</span> <span class="nav-text">2.10 样式的继承</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A0%B7%E5%BC%8F%E7%9A%84%E5%86%B2%E7%AA%81%E4%B8%8E%E4%BC%98%E5%85%88%E7%BA%A7%E9%97%AE%E9%A2%98"><span class="nav-number">18.</span> <span class="nav-text">2.11 样式的冲突与优先级问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%95%BF%E5%BA%A6%E5%8D%95%E4%BD%8D"><span class="nav-number">19.</span> <span class="nav-text">2.12 长度单位</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%A2%9C%E8%89%B2%E5%8D%95%E4%BD%8D"><span class="nav-number">20.</span> <span class="nav-text">2.13 颜色单位</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%96%87%E6%A1%A3%E6%B5%81%E4%B8%8E%E7%9B%92%E5%AD%90%E6%A8%A1%E5%9E%8B"><span class="nav-number"></span> <span class="nav-text">3. 文档流与盒子模型</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%87%E6%A1%A3%E6%B5%81"><span class="nav-number">1.</span> <span class="nav-text">3.1 文档流</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E6%A8%A1%E5%9E%8B%E5%9F%BA%E7%A1%80"><span class="nav-number">2.</span> <span class="nav-text">3.2 盒子模型基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E7%9A%84%E8%BE%B9%E6%A1%86"><span class="nav-number">3.</span> <span class="nav-text">3.3 盒子的边框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E7%9A%84%E5%86%85%E8%BE%B9%E8%B7%9D"><span class="nav-number">4.</span> <span class="nav-text">3.4 盒子的内边距</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A4%96%E8%BE%B9%E8%B7%9D"><span class="nav-number">5.</span> <span class="nav-text">3.5 外边距</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E7%9A%84%E6%B0%B4%E5%B9%B3%E5%B8%83%E5%B1%80%E9%87%8D%E8%A6%81"><span class="nav-number">6.</span> <span class="nav-text">3.6 盒子的水平布局(重要)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E6%A8%A1%E5%9E%8B%E5%9E%82%E7%9B%B4%E6%96%B9%E5%90%91%E5%B8%83%E5%B1%80"><span class="nav-number">7.</span> <span class="nav-text">3.7 盒子模型垂直方向布局</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A4%96%E8%BE%B9%E8%B7%9D%E6%8A%98%E5%8F%A0%E9%97%AE%E9%A2%98"><span class="nav-number">8.</span> <span class="nav-text">3.8 外边距折叠问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%8C%E5%86%85%E5%85%83%E7%B4%A0%E7%9A%84%E7%9B%92%E5%AD%90%E6%A8%A1%E5%9E%8B"><span class="nav-number">9.</span> <span class="nav-text">3.9 行内元素的盒子模型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%BB%98%E8%AE%A4%E6%A0%B7%E5%BC%8F%E9%87%8D%E7%BD%AE%E6%A0%B7%E5%BC%8F%E8%A1%A8"><span class="nav-number">10.</span> <span class="nav-text">3.10 默认样式(重置样式表)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E5%B0%BA%E5%AF%B8%E7%9A%84%E8%AE%A1%E7%AE%97%E6%96%B9%E5%BC%8F"><span class="nav-number">11.</span> <span class="nav-text">3.11 盒子尺寸的计算方式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%92%E5%AD%90%E7%9A%84%E8%BD%AE%E5%BB%93%E5%92%8C%E5%9C%86%E8%A7%92"><span class="nav-number">12.</span> <span class="nav-text">3.12 盒子的轮廓和圆角</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%B5%AE%E5%8A%A8%E5%B8%83%E5%B1%80"><span class="nav-number"></span> <span class="nav-text">4. 浮动布局</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B5%AE%E5%8A%A8%E7%AE%80%E4%BB%8B"><span class="nav-number">1.</span> <span class="nav-text">4.1 浮动简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B5%AE%E5%8A%A8%E7%9A%84%E7%89%B9%E7%82%B9"><span class="nav-number">2.</span> <span class="nav-text">4.2 浮动的特点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%AB%98%E5%BA%A6%E5%A1%8C%E9%99%B7%E9%97%AE%E9%A2%98"><span class="nav-number">3.</span> <span class="nav-text">4.3 高度塌陷问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#bfc%E6%9C%80%E4%BC%98%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88"><span class="nav-number">4.</span> <span class="nav-text">4.4 BFC最优解决方案</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%9A%E4%BD%8D"><span class="nav-number"></span> <span class="nav-text">5 定位</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%9A%E4%BD%8D%E7%9A%84%E7%AE%80%E4%BB%8B"><span class="nav-number">1.</span> <span class="nav-text">5.1 定位的简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%9D%E5%AF%B9%E5%AE%9A%E4%BD%8D"><span class="nav-number">2.</span> <span class="nav-text">5.2 绝对定位</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9B%BA%E5%AE%9A%E5%AE%9A%E4%BD%8D"><span class="nav-number">3.</span> <span class="nav-text">5.3 固定定位</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%B2%98%E6%BB%9E%E5%AE%9A%E4%BD%8D"><span class="nav-number">4.</span> <span class="nav-text">5.4 粘滞定位</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B0%B4%E5%B9%B3%E5%9E%82%E7%9B%B4%E5%B8%83%E5%B1%80"><span class="nav-number">5.</span> <span class="nav-text">5.5 水平垂直布局</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%83%E7%B4%A0%E7%9A%84%E5%9E%82%E7%9B%B4%E5%B1%82%E7%BA%A7"><span class="nav-number">6.</span> <span class="nav-text">5.6 元素的垂直层级</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%A1%A8%E6%A0%BC%E4%B8%8E%E8%A1%A8%E5%8D%95"><span class="nav-number"></span> <span class="nav-text">6 表格与表单</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%A8%E6%A0%BC"><span class="nav-number">1.</span> <span class="nav-text">6.1 表格</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%95%BF%E8%A1%A8%E6%A0%BC"><span class="nav-number">2.</span> <span class="nav-text">6.2 长表格</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%A8%E6%A0%BC%E7%9A%84%E6%A0%B7%E5%BC%8F"><span class="nav-number">3.</span> <span class="nav-text">6.3 表格的样式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%A8%E5%8D%95"><span class="nav-number">4.</span> <span class="nav-text">6.4 表单</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%A8%E5%8D%95%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="nav-number">5.</span> <span class="nav-text">6.5 表单的属性</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8A%A8%E7%94%BB%E4%B8%8E%E8%BF%87%E6%B8%A1"><span class="nav-number"></span> <span class="nav-text">7 动画与过渡</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%BF%87%E6%B8%A1"><span class="nav-number">1.</span> <span class="nav-text">7.1过渡</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A8%E7%94%BB"><span class="nav-number">2.</span> <span class="nav-text">7.2 动画</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%98%E5%BD%A2"><span class="nav-number">3.</span> <span class="nav-text">7.3 变形</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%BC%B9%E6%80%A7%E5%AE%B9%E5%99%A8%E4%B8%8E%E7%A7%BB%E5%8A%A8%E7%AB%AF"><span class="nav-number"></span> <span class="nav-text">8 弹性容器与移动端</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%B9%E6%80%A7%E7%9B%92%E4%BC%B8%E7%BC%A9%E7%9B%92%E5%AD%90"><span class="nav-number">1.</span> <span class="nav-text">8.1 弹性盒&#x2F;伸缩盒子</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%B9%E6%80%A7%E5%AE%B9%E5%99%A8%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-number">2.</span> <span class="nav-text">8.2 弹性容器的使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%B9%E6%80%A7%E5%85%83%E7%B4%A0%E7%9A%84%E6%A0%B7%E5%BC%8F"><span class="nav-number">3.</span> <span class="nav-text">8.3 弹性元素的样式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%83%8F%E7%B4%A0%E4%B8%8E%E8%A7%86%E5%8F%A3"><span class="nav-number">4.</span> <span class="nav-text">8.4 像素与视口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%A7%BB%E5%8A%A8%E7%AB%AF%E4%BB%8B%E7%BB%8D"><span class="nav-number">5.</span> <span class="nav-text">8.5 移动端介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%86%E5%8F%A3"><span class="nav-number">6.</span> <span class="nav-text">8.6 视口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#vm%E9%80%82%E9%85%8D"><span class="nav-number">7.</span> <span class="nav-text">8.7 vm适配</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%93%8D%E5%BA%94%E5%BC%8F%E5%B8%83%E5%B1%80"><span class="nav-number">8.</span> <span class="nav-text">8.8 响应式布局</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AA%92%E4%BD%93%E7%89%B9%E6%80%A7"><span class="nav-number">9.</span> <span class="nav-text">8.9 媒体特性</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AD%97%E4%BD%93%E5%9B%BE%E6%A0%87%E5%AD%97%E4%BD%93%E4%B8%8E%E6%B8%90%E5%8F%98"><span class="nav-number"></span> <span class="nav-text">9 字体,图标字体与渐变</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E4%BD%93"><span class="nav-number">1.</span> <span class="nav-text">9.1 字体</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9B%BE%E6%A0%87%E5%AD%97%E4%BD%93"><span class="nav-number">2.</span> <span class="nav-text">8.2 图标字体</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E4%BD%93%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="nav-number">3.</span> <span class="nav-text">8.3 字体的属性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%87%E6%9C%AC%E6%A0%B7%E5%BC%8F"><span class="nav-number">4.</span> <span class="nav-text">8.4 文本样式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%83%8C%E6%99%AF"><span class="nav-number">5.</span> <span class="nav-text">8.5 背景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B8%90%E5%8F%98"><span class="nav-number">6.</span> <span class="nav-text">8.6 渐变</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Liu Kairui"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Liu Kairui</p>
  <div class="site-description" itemprop="description">LiuKairui Persional Website</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">45</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/KairuiLiu" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;KairuiLiu" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:tclkr@live.com" title="E-Mail → mailto:tclkr@live.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://qm.qq.com/cgi-bin/qm/qr?k=oaf3ToOlN17hr5sHV98bT8qxsNYGaw5L&noverify=0" title="QQ → https:&#x2F;&#x2F;qm.qq.com&#x2F;cgi-bin&#x2F;qm&#x2F;qr?k&#x3D;oaf3ToOlN17hr5sHV98bT8qxsNYGaw5L&amp;noverify&#x3D;0" rel="noopener" target="_blank"><i class="fab fa-qq fa-fw"></i>QQ</a>
      </span>
      <span class="links-of-author-item">
        <a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-rss fa-fw"></i>RSS</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://liukairui.blog.csdn.net/" title="CSDN → https:&#x2F;&#x2F;liukairui.blog.csdn.net" rel="noopener" target="_blank"><i class="fab fa-cuttlefish fa-fw"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://liukairui.cc/" title="国内站点 → http:&#x2F;&#x2F;liukairui.cc" rel="noopener" target="_blank"><i class="fa fa-globe fa-fw"></i>国内站点</a>
      </span>
  </div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="https://cdnjs.cloudflare.com/ajax/libs/creativecommons-vocabulary/2020.11.3/assets/license_badges/small/by_nc_sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll site-overview-item animated">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://paste.ubuntu.com/" title="https:&#x2F;&#x2F;paste.ubuntu.com&#x2F;" rel="noopener" target="_blank">Ubuntu Pastebin</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://send.firefox.com/" title="https:&#x2F;&#x2F;send.firefox.com&#x2F;" rel="noopener" target="_blank">Firefox Send</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://jkwzs.cn/" title="https:&#x2F;&#x2F;jkwzs.cn&#x2F;" rel="noopener" target="_blank">南花醉笔丶の个人博客</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://ywrby.cn/" title="https:&#x2F;&#x2F;ywrby.cn&#x2F;" rel="noopener" target="_blank">Ywrby个人博客</a>
        </li>
    </ul>
  </div>

        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://liukairui.me/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Liu Kairui">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="LiuKairui Website">
      <meta itemprop="description" content="LiuKairui Persional Website">
    </span>
    
    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="HTML&CSS学习笔记 | LiuKairui Website">
      <meta itemprop="description" content="HTML&CSS入门笔记,主讲:尚硅谷李立超,视频来自B站:BV1XJ411X7Ud">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          HTML&CSS学习笔记
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-10-31 00:00:19" itemprop="dateCreated datePublished" datetime="2020-10-31T00:00:19+08:00">2020-10-31</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">前端</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%89%8D%E7%AB%AF/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%89%8D%E7%AB%AF/HTML/" itemprop="url" rel="index"><span itemprop="name">HTML</span></a>
        </span>
    </span>

  
    <span id="/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-meta-item leancloud_visitors" data-flag-title="HTML&CSS学习笔记" title="阅读次数">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span class="leancloud-visitors-count"></span>
    </span>
  
  <span class="post-meta-item">
    
    <span class="post-meta-item-icon">
      <i class="far fa-comment"></i>
    </span>
    <span class="post-meta-item-text">Valine：</span>
  
    <a title="valine" href="/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

<script>
    CONFIG.hostname = location.hostname;
</script>
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>22k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>20 分钟</span>
    </span>
</div>

            <div class="post-description">HTML&CSS入门笔记,主讲:尚硅谷李立超,视频来自B站:BV1XJ411X7Ud</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="html基础">1. HTML基础</h2>
<h3 id="网页的结构">1.1 网页的结构</h3>
<p><strong>前端的三种语言</strong>：HTML(结构)，CSS(表现)，JavaScript(行为)</p>
<p><strong>标准</strong>：W3C</p>
<p><strong>基本结构</strong></p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
    元数据，给浏览器搜索引擎看的
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
	想要被看到的内容
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">></span></span></code></pre>
<p>标签一般成对出现但是存在自结束标签，例如<code>&lt;input&gt;</code>,<code>&lt;img&gt;</code>,H5不推荐写自结束的<code>/</code></p>
<p><strong>注释的写法</strong><code>&lt;!-- 这是一个注释 --&gt;</code>，<strong>注释不能嵌套</strong></p>
<p><strong>标签的属性：</strong>在标签的开始/自结束标签前面写，是一个名值对结构</p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span>这是我的<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>font</span> <span class="token attr-name">color</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Red<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>第三个<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>font</span><span class="token punctuation">></span></span>网页<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span></code></pre>
<p>属性之间空格隔开</p>
<p><strong>网页的基本结构：</strong></p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">doctype</span> <span class="token name">html</span><span class="token punctuation">></span></span>   html5声明
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>utf-8<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        字符集应该与编辑器的一致
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">></span></span></code></pre>
<ul>
<li>迭代： HTML4、XHTML2.0、HTML5...</li>
<li>文档声明(doctype)：文档声明告诉浏览器网页的版本<code>&lt;doctype html&gt;</code></li>
<li>计算机的最小操作单位是 <em>1byte=8bit</em></li>
<li>乱码问题：如果编码解码字符集不同就会有乱码问题</li>
<li>设置charset应该与编辑器的编码一致</li>
</ul>
<p><strong><code>&lt;html lang="en"&gt;</code></strong>
告诉浏览器你写的是英文网站，到时候会弹出是否翻译，中文则为<code>&lt;html lang="zh"&gt;</code></p>
<h3 id="html中的实体">1.2 HTML中的"实体"</h3>
<p>在网页中，编写的多个空格会自动被浏览器解析为一个空格，目的是方便格式化代码<br />
但是在html中有时候不能书写一些特殊符号，比如字母两侧的 '&lt;' '&gt;' 号
那么我们就需要实体(转义字符)语法是"&amp;"开头";"结尾，例如</p>
<ul>
<li><code>&amp;nbsp;</code> 是空格</li>
<li><code>&amp;gt;</code> 是大于</li>
<li><code>&amp;lt;</code> 是小于</li>
<li><code>&amp;copy;</code>是版权号</li>
</ul>
<p>例如</p>
<pre class="language-html" data-language="html"><code class="language-html">a &lt; b > c
a<span class="token entity named-entity" title="&lt;">&amp;lt;</span>b<span class="token entity named-entity" title="&gt;">&amp;gt;</span>c
a<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>b</span><span class="token punctuation">></span></span>c</code></pre>
<h3 id="meta-标签">1.3 meta 标签</h3>
<p>meta主要用于设置网页的元数据，元数据是并不是给用户看的，其组成有两个</p>
<ul>
<li>name 指定数据名称</li>
<li>content 指定数据内容</li>
</ul>
<p>值得注意的是meta并不是键，name才是，例如<code>&lt;meta charset="UTF-8"&gt;</code>中charset是键，UTF-8是值。常见的键值对包括</p>
<ul>
<li>charset: 网页采用的字符集，他的写法是另一种键值对的，见下</li>
<li>keywords: 搜索引擎用的关键词，用逗号隔开</li>
<li>description: 搜索引擎蓝字下面的那个</li>
<li>auther: 作者</li>
<li>title: 标题，会作为搜索引擎的结果标题表示</li>
<li>http-equiv 协议，其中http-equiv="refresh" 几秒后跳转网页到</li>
</ul>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>UTF-8<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>keywords<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>HTML5,前端，CSS<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>description<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>LaLaLaLaLaLaLaLa<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">http-equiv</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>refresh<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>3;url=http://www.swu.edu.cn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> </code></pre>
<h2 id="语义化标签">1.4 语义化标签</h2>
<p>语义化标签在HTML中表示特定的结构，但是会在显示的时候存在样式的变化。但是注意HTML是专门负责网页结构的，所以在使用html标签时应该关注的是标签的语义而不是标签的样式</p>
<ul>
<li><p>标题标签</p>
<ul>
<li><p><code>h1</code>~<code>h6</code>一共有6级标题，重要性递减</p></li>
<li><p><code>h1</code>是最重要的仅次于<code>title</code>，一般只有一个<code>h1</code></p></li>
<li><p>一般只用到<code>h1</code>到<code>h3</code></p></li>
</ul></li>
<li><p><code>p</code>标签，表示一个段落，也是一个块元素</p></li>
<li><p><code>hgroup</code>标签：将h标题分组</p></li>
<li><p><code>em</code>是语音语调的加重，是一个行内元素</p></li>
<li><p><code>strong</code>表示强调</p></li>
<li><p><code>blockqueue</code> 表示一个长引用</p></li>
<li><p><code>q</code> 表示一个短引用</p></li>
<li><p><code>br</code> 换行</p></li>
</ul>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span>一级标题<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>二级标题<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span>123<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span>456<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>hgroup</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span>回乡偶书<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>其一<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>hgroup</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span>今天天气<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>em</span><span class="token punctuation">></span></span>真<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>em</span><span class="token punctuation">></span></span>不错<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span>你今天必须要<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">></span></span>完成作业<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span>

鲁迅说：
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>blockquote</span><span class="token punctuation">></span></span>我是从来没有说过的<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>blockquote</span><span class="token punctuation">></span></span>

子曰<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>q</span><span class="token punctuation">></span></span>学而时习之<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>q</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
今天天气真不错</code></pre>
<ul>
<li><p>块元素：主要对元素进行布局</p></li>
<li><p>行内元素：用来包裹文字，一般是块内放行内</p></li>
</ul>
<p><code>p</code>元素里不能放任何块元素,浏览器会对网页自动修正，例如在html外的元素，把<code>h1</code>放在<code>p</code>里面，浏览器不会再源码里纠正，但是会在加载的内存中纠正，在检查元素中显示纠正结果</p>
<p>结构化语义标签(用的不多) - header: 网页头部 - main:
网页的主体部分(只有一个) - footer: 网页底部 - nav: 网页的导航 - aside:
侧注释，与主体相关的其他内容 - article 独立的文章 - section:
其他的独立区块</p>
<p>结构化无意义标签</p>
<ul>
<li>div: 没有语义，表示一个独立区块</li>
<li>span: 行内元素，没有语义，用来选中文字</li>
</ul>
<h2 id="列表">1.7 列表</h2>
<ul>
<li>无序列表 ul</li>
<li>有序列表 ol</li>
<li>定义列表 dl
<ul>
<li>dt 定义的内容</li>
<li>dd 对定义进行解释说明</li>
</ul></li>
<li>内容用 li</li>
</ul>
<p>列表间可以互相嵌套 <pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>结构<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>表现<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>行为<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ol</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>结构<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>表现<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>行为<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ol</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dl</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dt</span><span class="token punctuation">></span></span>结构<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dt</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span><span class="token punctuation">></span></span>解释解释解释解释<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span><span class="token punctuation">></span></span>解释解释解释解释<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span><span class="token punctuation">></span></span>解释解释解释解释4<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dl</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ol</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>结构<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>表现<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>行为<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ol</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>表现<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span>行为<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">></span></span></code></pre></p>
<h2 id="超链接">1.8 超链接</h2>
<p>超链接让页面跳转到另一个位置或者其他页面</p>
<p>用a定义超链接 a是一个行内元素可以嵌套除他自身以外块的元素</p>
<p>a的属性：</p>
<ul>
<li>href:目标跳转路径
<ul>
<li>值可以是外部网站地址，也可以是内部页面地址</li>
<li>#是回到顶部</li>
<li>#ID跳转到页面指定位置</li>
<li>在开发中可以用javascript:;这样什么也不发生</li>
</ul></li>
<li>target属性，可选值
<ul>
<li>_self 默认值，在当前页面打开</li>
<li>_blank 在新的页面打开</li>
</ul></li>
</ul>
<p><strong>注意</strong>：ID是唯一属性，不能一样，字母开头，区分大小写，靠前的元素优先生效</p>
<p>例如</p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>07.列表.html<span class="token punctuation">"</span></span> <span class="token attr-name">target</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>_blank<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>超链接<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#but<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>去底部<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>javascript:;<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>什么也不发生<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>a</span><span class="token punctuation">></span></span></code></pre>
<h2 id="图">1.9 图</h2>
<p>img标签用于引入图片</p>
<p>使用img标签引入外部标签，img是一个自结束标签</p>
<p>img
属于替换元素，属于行内元素和替换元素之间的一种元素，即img这段代码被具体的东西给替换了</p>
<p>属性：</p>
<ul>
<li>src 属性指定的外部路劲</li>
<li>alt
对于图片的描述，描述默认情况下是不会显示的，会在图片显示不出来的时候显示，搜索引擎会通过alt来搜索图片</li>
<li>width 指定图片的宽度(单位是像素)</li>
<li>height 指定图片的高度(单位是像素)</li>
</ul>
<p><strong>注意</strong>：如果只修改了一个，图片会被等比例缩放，如果指定了两个图片就不会等比例变化</p>
<p><strong>注意</strong>：一般在PC端不建议修改图片的大小，为了节省网络资源，最好直接在做图的时候改好,但是在移动端经常会把图片缩小</p>
<p>图片的格式：</p>
<ul>
<li>jpg(jpeg)
<ul>
<li>颜色多，不支持透明，不支持动图</li>
<li>一般用于显示照片</li>
</ul></li>
<li>gif
<ul>
<li>支持的颜色少，支持简单透明，支持动图</li>
<li>颜色单一的动图</li>
</ul></li>
<li>png
<ul>
<li>颜色丰富，支持透明，不支持动图</li>
<li>颜色丰富，复杂透明(转为网页而生)</li>
</ul></li>
<li>webp
<ul>
<li>谷歌新推出的，专业用于网络的格式</li>
<li>具有其他图片格式的优点，文件特别小</li>
<li>兼容性不好(例如IE)</li>
</ul></li>
<li>base64
<ul>
<li>使用base64进行编码，这样可以直接把图片转化为字符，通过字符格式引入</li>
<li>一般都是需要与网页一起加载的图片</li>
</ul></li>
</ul>
<p><strong>原则</strong>：效果一样用小的(快)，效果不一样用效果好的</p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./img/img/1.gif<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span> <span class="token attr-name">width</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span>100px</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./img/img/5.gif<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>松鼠<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1763336060,2397496866&amp;fm=26&amp;gp=0.jpg<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
&lt;img src="data:image/jpeg;base64...code...></code></pre>
<h2 id="内联框架">1.10 内联框架</h2>
<p>内联框架，用于向当前页面中引入其他页面</p>
<ul>
<li><p>src 指定要引入的网页路径</p></li>
<li><p>frameborder 只有0/1 就是显示与不显示边框</p></li>
</ul>
<p>内联框架是把一个网页做为窗口引入现在的网页，注意的是<strong>内联框架的内容不会被搜索框架所索引</strong></p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>iframe</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://www.qq.com<span class="token punctuation">"</span></span> <span class="token attr-name">frameborder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0<span class="token punctuation">"</span></span> <span class="token attr-name">width</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span>800</span> <span class="token attr-name">height</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span>400</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>iframe</span><span class="token punctuation">></span></span></code></pre>
<h2 id="音视频">1.11 音视频</h2>
<p>audio
向网页引入音频文件，音视频文件引入的时候默认情况下是不允许用户操作的</p>
<p>属性:</p>
<ul>
<li>controls 只有键没有值 是否允许用户控制播放</li>
<li>autoplay 音频是否自动播放(兼容性差，例如火狐不自动播放)</li>
</ul>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>audio</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/audio.mp3<span class="token punctuation">"</span></span> <span class="token attr-name">controls</span> <span class="token attr-name">autoplay</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>audio</span><span class="token punctuation">></span></span></code></pre>
<p>除了通过src实现之外，还可以通过source实现,这样可以实现对于不同浏览器提供最佳匹配文件,IE8不支持，所以要输出提示，原理是：进入<code>audio</code>标签，如果匹配到source,那么浏览器会自动忽略内部其他代码，实现选择，IE8不认识source所以会自动忽略所有<code>source</code>标签，于是只找到提示信息，自动不全<code>p</code>标签，输出提示</p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>audio</span> <span class="token attr-name">controls</span><span class="token punctuation">></span></span>
    对不起你的浏览器不支持播放音频，请升级浏览器
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>source</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/audio.mp3<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>source</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/audio.ogg<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>embed</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/audio.mp3<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>audio</span><span class="token punctuation">></span></span></code></pre>
<p>视频标签是<code>video</code>，同理 <pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>video</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/flower.mp4<span class="token punctuation">"</span></span> <span class="token attr-name">controls</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>video</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>video</span> <span class="token attr-name">controls</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>source</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/flower.webm<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>source</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/flower.mp4<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>embed</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./source/flower.mp4<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>video</span><span class="token punctuation">></span></span></code></pre> # 2. CSS基础</p>
<h2 id="css简介">2.1 CSS简介</h2>
<p>网页的三个部分</p>
<ul>
<li>结构HTML</li>
<li>表现CSS</li>
<li>行为JS</li>
</ul>
<p>CSS</p>
<ul>
<li>层叠样式表</li>
<li>网页实际上是一个多层的结构，通过css样式可以对网页的每一个层设置样式，最后可以看到的只有最上层的</li>
</ul>
<p>CSS的定义方式</p>
<ul>
<li>第一种方式：
<ul>
<li>在标签内部通过style设置元素的样式</li>
<li>问题：
如果希望影响到多个元素，必须在多个元素复制一遍，当样式发送变化时要一个一个修改，非常不方便</li>
<li>注意：开发时候绝对不要使用</li>
</ul></li>
<li>第二种方式：
<ul>
<li>将样式编写到style标签里</li>
<li>通过css选择器为多个标签设置样式，并且只修改一次</li>
<li>更方便对样式进行复用</li>
<li>问题：
<ul>
<li>只对一个网页起作用</li>
<li>里面的样式不能跨网页复用</li>
</ul></li>
</ul></li>
<li>第三种方式
<ul>
<li>将css样式写到一个css文件里 通过link链接外部css文件</li>
<li>写到外面可以触发浏览器的缓存机制，从而加快网页的加载速度，提高用户的体验</li>
</ul></li>
</ul>
<h2 id="css基本语法">2.2 CSS基本语法</h2>
<ul>
<li><p>注释是<code>/*...*/</code>，会被浏览器自动忽略</p></li>
<li><p>选择器&amp;申明块</p>
<p>通过选择器选定指定页面,比如p的作用就是选中所有的p元素,申明块，通过声明块来为指定的元素设置演样式声明块是一个名值对的一个样式，名值对之间以:链接，以;结尾</p></li>
</ul>
<h2 id="css-选择器基础">2.3 CSS 选择器基础</h2>
<p>class是标签属性，和id类似，不同的是class可以重复使用</p>
<ul>
<li><p>元素选择器</p>
<ul>
<li>作用，根据标签名确定指定元素</li>
<li>语法：标签名{}</li>
</ul></li>
<li><p>ID选择器</p>
<ul>
<li>作用，根据元素的ID属性选中一个元素</li>
<li>语法，#ID属性值</li>
<li>例子，#box{},#red{}</li>
</ul></li>
<li><p>class</p>
<ul>
<li>多个元素可以绑定一个class</li>
<li>一个元素可以绑定多个class(用空格隔开)</li>
<li>语法 .class 属性值</li>
</ul></li>
<li><p>统配选择器：</p>
<ul>
<li>*{}</li>
</ul></li>
</ul>
<h2 id="css的复合选择器">2.4 CSS的复合选择器</h2>
<ul>
<li><p>交集选择器，同时选择有几个类的元素，两个选择器直接写在一起
<strong>注意</strong>：交集选择器中如果有元素选择器，必须以元素选择器开头</p></li>
<li><p>并集选择器，同时选择多个选择器对应的元素，用<code>,</code>分割开
<pre class="language-css" data-language="css"><code class="language-css"><span class="token selector">#b1,p,h1.red</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span></code></pre></p></li>
</ul>
<h2 id="关系选择器">2.5 关系选择器</h2>
<ul>
<li>父元素
<ul>
<li>直接包含子元素的元素就是父元素</li>
</ul></li>
<li>子元素
<ul>
<li>直接被父元素包含的元素</li>
</ul></li>
<li>祖先元素
<ul>
<li>直接或间接包含后代的元素就是祖先元素</li>
<li>一个元素是父元素也是他的祖先元素</li>
</ul></li>
<li>后代元素
<ul>
<li>直接或间接被祖先包含的元素叫后代元素</li>
</ul></li>
<li>兄弟元素
<ul>
<li>拥有相同父元素的元素就是兄弟元素</li>
</ul></li>
</ul>
<p>选择器</p>
<ul>
<li><p>子元素选择器：</p>
<ul>
<li>作用：指定父元素的子元素</li>
<li>语法 父元素&gt;子元素</li>
</ul></li>
</ul>
<pre class="language-css" data-language="css"><code class="language-css"><span class="token selector">div.box>span</span><span class="token punctuation">&#123;</span>
    <span class="token property">color</span><span class="token punctuation">:</span>red<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span></code></pre>
<ul>
<li>下一个兄弟选择器
<ul>
<li>选择具有相同父亲的兄弟元素</li>
</ul></li>
</ul>
<pre class="language-css" data-language="css"><code class="language-css"><span class="token selector">p+span</span><span class="token punctuation">&#123;</span>
    <span class="token property">color</span><span class="token punctuation">:</span>blue<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span></code></pre>
<ul>
<li>下边所有的兄弟兄弟选择器
<ul>
<li>选择具有相同父亲的兄弟元素</li>
<li>语法:~</li>
</ul></li>
</ul>
<h2 id="属性选择器">2.6 属性选择器</h2>
<ul>
<li><code>[属性名]</code> 选择含有指定属性的元素</li>
<li><code>[属性名=属性值]</code> 选择含有指定属性和属性值的元素</li>
<li><code>[属性名^=属性值]</code> 以属性值开头的元素</li>
<li><code>[属性名$=属性值]</code> 以属性值结尾的元素</li>
<li><code>[属性名*=属性值]</code> 以属性值含有某值的元素</li>
</ul>
<pre class="language-css" data-language="css"><code class="language-css"><span class="token selector">p[title=abc]</span><span class="token punctuation">&#123;</span>
    <span class="token property">color</span><span class="token punctuation">:</span>orange<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>

<span class="token selector">p[title^=abc]</span><span class="token punctuation">&#123;</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span></code></pre>
<h2 id="伪类选择器">2.7 伪类选择器</h2>
<p>伪类：不存在的元素，特殊的类</p>
<ul>
<li>伪类用来描述一个元素的特殊形态，比如第一个子元素，被点击的元素，鼠标移入的元素</li>
<li>伪类一般情况下是使用:开头
<ul>
<li>:first-child
第一个元素(不是说同类的第一个子元素，是所有子元素的子元素)</li>
<li>:last-child 最后一个子元素</li>
<li>:nth-child() 选中第n个子元素
<ul>
<li>如果直接写n，相当于是0-INF</li>
<li>如果直接写2n，相当于是所有偶数元素</li>
<li>如果直接写2n+1，相当于是所有奇数元素(有3)</li>
<li>odd/even</li>
</ul></li>
</ul></li>
<li>加type的child
<ul>
<li>:first-of-type</li>
<li>:last-of-type</li>
<li>:nth-of-type</li>
</ul></li>
<li>not是否定伪类
<ul>
<li>将符合条件的元素从选择器去除</li>
</ul></li>
</ul>
<h2 id="a元素的伪类选择器">2.8 <code>a</code>元素的伪类选择器</h2>
<ul>
<li><code>a:link&#123;...&#125;</code>:正常的链接</li>
<li><code>a:visited&#123;...&#125;</code>:访问过的链接，<strong>出于用户隐私考虑，visited只能改颜色</strong></li>
<li><code>a:active&#123;...&#125;</code>:鼠标点击</li>
<li><code>a:hover&#123;...&#125;</code>: 鼠标移入</li>
</ul>
<p>注意的是伪类一定要按照以上顺序写:<code>link</code>,<code>visited</code>,<code>active</code>,<code>hover</code>(LoVe
A Ha)</p>
<h2 id="伪元素选择器">2.9 伪元素选择器</h2>
<p>伪元素表示页面中并不真实存在的一些元素(特殊的位置)，使用<code>::</code>开头</p>
<ul>
<li>::first-letter</li>
<li>::first-line</li>
<li>::selection 选中的内容</li>
<li>::before</li>
<li>::after,<strong>注意</strong>:必须结合content结合使用</li>
</ul>
<h2 id="样式的继承">2.10 样式的继承</h2>
<p>我们为一个元素设置的样式也会应用到他的后代元素</p>
<p>继承是发生在祖先与后代之间的</p>
<p>继承的设计师为了开发，利用继承只需写一次就可以让所有的元素都具有该样式</p>
<p><strong>注意</strong>：并不是所有的样式都可以被继承，比如背景相关的，布局相关的样式都不会被继承</p>
<h2 id="样式的冲突与优先级问题">2.11 样式的冲突与优先级问题</h2>
<p>当我们用不同的选择器选择相同的元素，并且为相同的样式设置不同的值，此时发生了样式的冲突</p>
<p>发生样式冲突的时候，显示的效果是由显示的优先级决定的</p>
<table>
<thead>
<tr class="header">
<th>选择器的权重</th>
<th>优先级</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>内联样式</td>
<td>1,0,0,0</td>
</tr>
<tr class="even">
<td>ID选择器</td>
<td>0,1,0,0</td>
</tr>
<tr class="odd">
<td>类和伪类选择器</td>
<td>0,0,1,0</td>
</tr>
<tr class="even">
<td>元素选择器</td>
<td>0,0,0,1</td>
</tr>
<tr class="odd">
<td>通配选择器</td>
<td>0,0,0,0</td>
</tr>
<tr class="even">
<td>继承的样式</td>
<td>没有优先级</td>
</tr>
</tbody>
</table>
<ul>
<li><p>比较优先级的时候要把所有的<strong>求和</strong>计算，最后优先级高的优先显示，分组选择器单独计算</p></li>
<li><p>选择器累加不会超过下一级的，也就是不进位，如果优先级计算后相同优先使用考下的样式</p></li>
<li><p>在属性结束后加上 !important; 会获取最高优先级，慎用！！</p></li>
</ul>
<h2 id="长度单位">2.12 长度单位</h2>
<ul>
<li>像素
<ul>
<li>显示器实际上是由一个一个发光的小点构成的</li>
<li>不同屏幕像素大小不同</li>
<li>所以同样的200像素在不同的设备下显示效果不一样</li>
</ul></li>
<li>百分比
<ul>
<li>相对于父元素的百分比</li>
<li>使得子元素随着父元素改变而改变</li>
</ul></li>
<li>em
<ul>
<li>随着字体大小的改变而改变</li>
<li>1个em是一个字的大小，字的大小可以在div内部修改，即字体大小是自身的字体大小</li>
</ul></li>
<li>rem
<ul>
<li>1个rem是相对根元素的字体大小而变化</li>
<li>经常用于移动端开发</li>
</ul></li>
</ul>
<h2 id="颜色单位">2.13 颜色单位</h2>
<p>在css中可以直接使用颜色名来配置各种颜色，但是直接使用颜色名来命名是非常不方便的</p>
<ul>
<li>RGB值
<ul>
<li>RGB是通过不同的颜色浓度调配处不同的颜色</li>
<li>每一种颜色是在0-255或者0-100%</li>
<li>语法: RGB(xx,xx,xx)</li>
</ul></li>
<li>RGBA值
<ul>
<li>在RGB基础上多了个透明度值A</li>
<li>范围0-1,1是完全不透明</li>
<li>语法: RGBA(xx,xx,xx,xx)</li>
</ul></li>
<li>16进制的RGB
<ul>
<li>语法#RGB</li>
<li>颜色浓度00-ff</li>
<li>如果两位两位重复，例如#AABBCC可以写成#ABC</li>
</ul></li>
<li>HSL和HSLA值
<ul>
<li>在工业设计使用多</li>
<li>H色相(0-360)</li>
<li>S饱和度(浓度0-100)</li>
<li>L亮度(亮度0-100)</li>
</ul></li>
</ul>
<h1 id="文档流与盒子模型">3. 文档流与盒子模型</h1>
<h2 id="文档流">3.1 文档流</h2>
<ul>
<li>我们认为网页是一个多层结构，是一层一层的</li>
<li>可以通过css为每一次设置样式</li>
<li>用户只能看到最上面的一层</li>
<li>我们称最下面的一层叫文档流，文档流是网页的基础
我们创建的元素默认是在文档流中进行排列</li>
<li>对于我们来说元素主要有两种状态
<ul>
<li>在文档流中</li>
<li>不在文档流中</li>
</ul></li>
<li>元素在文档流中的特点：
<ul>
<li>块元素 -在页面中会独占一行
<ul>
<li>默认宽度是占满父元素</li>
<li>默认高度是被子元素撑开</li>
</ul></li>
<li>行内元素
<ul>
<li>不会独占页面的一行，值占自身大小</li>
<li>自左向右排列</li>
<li>和书写习惯一致</li>
<li>行内元素默认的高度和宽度都是被内容撑开</li>
</ul></li>
</ul></li>
</ul>
<h2 id="盒子模型基础">3.2 盒子模型基础</h2>
<ul>
<li>CSS将页面全部元素设置为了一个矩形的盒子</li>
<li>将元素设置为矩形的盒子之后，对网页的布局就变成了对不同盒子放在不同的位置</li>
<li>每一个盒子都有以下几个部分
<ul>
<li>内容区(content)</li>
<li>内边距(padding)</li>
<li>边框(border)</li>
<li>外边距(margin)</li>
</ul></li>
</ul>
<p>内容区的设置，大小和高度默认设置的是内容区属性<br />
边框属于盒子的边缘，我们需要设置至少三个样式</p>
<ul>
<li>border-width</li>
<li>border-color</li>
<li>border-style</li>
</ul>
<p>边框的大小会影响到盒子的大小</p>
<ul>
<li>border-width: 10px;</li>
<li>border-color: red;</li>
<li>border-style: solid;</li>
</ul>
<h2 id="盒子的边框">3.3 盒子的边框</h2>
<p>指定四个方向边框粗细，不写默认是3px，写四个值就是上右下左三个值的时候，默认第四个值同第二个，两个的时候上下同，左右同</p>
<p>写下如下在吗 <pre class="language-html" data-language="html"><code class="language-html">border-color: red yellow green aliceblue; </code></pre>
可以看到边界是梯形而不是矩形，这是因为如果某部分被两个边框重合，那么中间切开，但是如果你只写了<code>border-left-style</code>就不会出现这个情况</p>
<ul>
<li>border-style属性:
<ul>
<li>solid 实线</li>
<li>dashed 虚线</li>
<li>double 双线</li>
<li>默认值是none</li>
</ul></li>
</ul>
<p>还有一个属性是border-XXX-YYY其中XXX取top,left...YYY取color,width...</p>
<p>border的简写属性，没有相对顺序,不能设置多项</p>
<h2 id="盒子的内边距">3.4 盒子的内边距</h2>
<ul>
<li>内容区的边框时间的距离</li>
<li>一共有四个内边距</li>
<li>内边距设置会影响盒子的大小</li>
<li>背景颜色会延伸到内边距上</li>
<li>盒子大小由内容区，边框，内边距共同决定</li>
</ul>
<h2 id="外边距">3.5 外边距</h2>
<ul>
<li>外边距不影响可见框的大小</li>
<li>外边距会影响盒子的位置</li>
<li>一共有四个外边距</li>
<li>元素会尽量的自左向右顺序排列，在默认情况下如果我们设置左上的边距会影响自己，右下会影响别人</li>
<li>也可以设置负值，但是元素会向左上移动</li>
<li>mergin不会影响元素的可见框的大小，但是会影响盒子的实际大小</li>
</ul>
<h2 id="盒子的水平布局重要">3.6 盒子的水平布局(重要)</h2>
<p>元素在父元素的位置由以下属性决定</p>
<ul>
<li>margin-left</li>
<li>border-left</li>
<li>padding-left</li>
<li>width</li>
<li>padding-right</li>
<li>border-right</li>
<li>margin-right</li>
</ul>
<p>一个元素在他的父元素中<br />
子<strong>元素的margin-left+border-left+padding-left+width+padding-right+border-right=父元素宽度(必须满足)</strong></p>
<p>等式不成立的时候，我们称他为<strong>过度约束</strong>，这个时候我们会<strong>自动调整</strong></p>
<ul>
<li>如果7个值中没有auto会先调整margin-right</li>
<li>这7个值中有三个可以设置为auto
<ul>
<li>width (默认是auto)</li>
<li>margin-left</li>
<li>margin-right</li>
</ul></li>
<li>如果某一个值为auto就会先自动调整那个值</li>
<li>如果一个宽度和一个外边距是auto，那么宽度会调整到最大</li>
<li>如果三个都是auto，那么宽度会是最大</li>
<li>如果外边距都是auto，那么两个auto会赋相同的值(常用这个特点实现水平居中)</li>
</ul>
<h2 id="盒子模型垂直方向布局">3.7 盒子模型垂直方向布局</h2>
<p><strong>盒子的高度默认的父元素高度被子元素撑开</strong></p>
<p>子元素在内容区中排列</p>
<ul>
<li>如果子元素的大小超过父元素则子元素会从父元素中溢出</li>
<li>使用overflow属性来设置父元素如何处理溢出的子元素</li>
</ul>
<p>可选值：</p>
<ul>
<li>visible：(默认值)子元素从父元素中溢出，在父元素的外部显示</li>
<li>hidden:溢出的元素将会被裁减而不显示</li>
<li>scroll:生成两个滚动条，通过两个滚动条实现浏览</li>
<li>auto：根据需要生成两个滚动条</li>
</ul>
<h2 id="外边距折叠问题">3.8 外边距折叠问题</h2>
<p>相邻的垂直方向的外边距会发生折叠现象</p>
<ul>
<li>相邻元素垂直外边距之间会发生重叠</li>
<li>兄弟元素
<ul>
<li>兄弟元素之间相邻垂直外边距会取较大值</li>
<li>特殊情况
<ul>
<li>如果两个一正一负取和</li>
<li>如果两个都是负数取绝对值较大的</li>
</ul></li>
</ul></li>
<li>父子元素
<ul>
<li>父子元素之间的外边距子元素会传递给父元素</li>
<li>父子外边距折叠会对页面造成影响</li>
</ul></li>
</ul>
<h2 id="行内元素的盒子模型">3.9 行内元素的盒子模型</h2>
<ul>
<li>width,height不支持设置宽度和高度</li>
<li>行内元素可以padding但是垂直方向不会影响布局</li>
<li>行内元素可以boarder但是垂直方向不会影响布局</li>
<li>行内元素不折叠，只相加</li>
<li>display 用来设置元素显示的类型，其可选值有
<ul>
<li>inline 设置为行内元素</li>
<li>blockn 行内转换块元素</li>
<li>inline-block 既可以设置宽度又不会独占一行,类似于替换元素</li>
<li>table 表格</li>
<li>none 隐藏，啥都没了</li>
<li>visibility: hidden; 隐藏了，但是占据位置</li>
</ul></li>
</ul>
<h2 id="默认样式重置样式表">3.10 默认样式(重置样式表)</h2>
<p>重置样式表有两个</p>
<ul>
<li><code>reset.css</code> 去除了所有的css样式</li>
<li><code>normalize.css</code> 是将css样式进行了统一但不去除</li>
</ul>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./css/reset.css<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./css/normalize.css<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></code></pre>
<h2 id="盒子尺寸的计算方式">3.11 盒子尺寸的计算方式</h2>
<p>默认情况下盒子的可见框大小是由内容区，内边距，边框共同确定的</p>
<p>box-size
可以设置盒子的计算方式，设置width，height的作用域，可选值：</p>
<ul>
<li>content-box 默认值，使用宽度高度设置内容区的大小</li>
<li>border-box 宽和高用来设定整个盒子可见区的大小</li>
</ul>
<h2 id="盒子的轮廓和圆角">3.12 盒子的轮廓和圆角</h2>
<p>outline
用来设置元素的轮廓线，用法和boarder一样，但是轮廓不影响可见框的大小</p>
<p>boxs-shadow用来设置元素的阴影效果，不影响页面布局</p>
<ul>
<li>两个参数是阴影的右偏移量 影印的下偏移量</li>
<li>第三个是影印的模糊半径</li>
<li>第四个是影印的颜色</li>
</ul>
<h1 id="浮动布局">4. 浮动布局</h1>
<h2 id="浮动简介">4.1 浮动简介</h2>
<p>通过浮动可以使一个元素向其父元素的左侧或者右侧移动，使用float属性设置元素的浮动</p>
<p>可选值：</p>
<ul>
<li>none 默认值元素不浮动</li>
<li>left 向左浮动</li>
<li>right 向右浮动</li>
</ul>
<p>元素设置浮动之后元素的水平布局等式<strong>不需要强制成立</strong></p>
<ul>
<li>元素设置浮动以后会完全从文档流脱离</li>
<li>元素下面还在文档流中的元素会向上一定</li>
</ul>
<p>浮动可以让元素横向排列</p>
<ol type="1">
<li>浮动元素会完全脱离文档流不占位置</li>
<li>设置浮动以后元素会向父元素的左侧或者右侧移动</li>
<li>浮动元素不会从父元素中移出</li>
<li>浮动元素向左右移动不会超过前面的元素</li>
<li>如果浮动元素上面是没有浮动的块元素则浮动无法上移</li>
<li>浮动元素不会超过他上面的兄弟元素最多最多一样高</li>
</ol>
<p>浮动的主要作用是让元素水平排列，通过浮动可以制作水平方向上的布局</p>
<h2 id="浮动的特点">4.2 浮动的特点</h2>
<p>浮动不会盖住文字，文字会自动环绕在浮动元素周围</p>
<p>元素从文档流脱离之后会发生变换</p>
<ul>
<li>块元素
<ol type="1">
<li>块元素不在独占一行</li>
<li>脱离文档流以后宽度和高度被内容撑开</li>
</ol></li>
<li>行内元素
<ol type="1">
<li>行内元素脱离文档流之后会变成块元素，长宽默认被内容撑开，但是可以设置
也就是不区分行内和块了</li>
</ol></li>
</ul>
<h2 id="高度塌陷问题">4.3 高度塌陷问题</h2>
<p><strong>BFC块级格式化环境</strong></p>
<ul>
<li>BFC是CSS中的一个隐藏的属性，可以为一个元素开启BFC，开启BFC元素会变成一个独立的布局区域</li>
<li>元素开启BFC之后的特点：
<ol type="1">
<li>开启BFC的元素不会被浮动元素所覆盖</li>
<li>开启BFC元素子元素和父元素的外边距不会重叠</li>
<li>开启BFC可以包含浮动的子元素</li>
</ol></li>
<li>可以通过特殊方式开启BFC
<ol type="1">
<li>设置元素浮动(不推荐)</li>
<li>将元素设置为行内块元素(不推荐)</li>
<li>overflow 这只非visible一般设置auto或者hidden</li>
</ol></li>
</ul>
<p><strong>高度塌陷问题</strong>：</p>
<p>在浮动布局中，父元素的高度默认被子元素撑开的子元素浮动以后会完全脱离文档流，子元素从文档流脱离将无法撑起父元素的高度，导致父元素高度丢失</p>
<p>父元素丢失以后，其下的元素会自动上移，导致页面布局混乱所以高度塌陷是浮动布局较常见的一个问题我们必须处理</p>
<h2 id="bfc最优解决方案">4.4 BFC最优解决方案</h2>
<p>直接引入clearfix类 <pre class="language-css" data-language="css"><code class="language-css"><span class="token selector">.clearfix::before,
.clearfix::after</span><span class="token punctuation">&#123;</span>
    <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">;</span>
    <span class="token property">display</span><span class="token punctuation">:</span> table<span class="token punctuation">;</span>
    <span class="token property">clear</span><span class="token punctuation">:</span> both<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span></code></pre> <pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box1 clearfix<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span></code></pre></p>
<p>原理比较简单，首先设置一个前后属性，里面填充一个空内容，但是如果是内联的话就不会显示，我们必须设置为非内联，为了解决外边距重叠问题，设置为<code>table</code>,最后为了解决BFC所以设置<code>clear:both</code></p>
<h1 id="定位">5 定位</h1>
<h2 id="定位的简介">5.1 定位的简介</h2>
<ul>
<li>定位是一种更加高级的布局手段</li>
<li>通过定位我们可以将元素摆放到页面的任何地方</li>
<li>使用position设置定位, 可选值
<ul>
<li>static 静止的，默认值，不开启定位</li>
<li>relatove 开启元素相对定位</li>
<li>absolute 开启元素绝对定位</li>
<li>fixed 开启 元素的固定定位</li>
<li>sticky 开启 元素的粘滞定位</li>
</ul></li>
<li>相对定位：
<ul>
<li>当元素的position时则开启了元素的相对定位</li>
<li>相对定位的特点
<ol type="1">
<li>元素开启相对定位以后如果不设置偏移量不会发生任何变化</li>
</ol></li>
</ul></li>
<li>偏移量(off-set)
<ul>
<li>当元素开启了定位之后可以通过偏移量设置元素的位置 top bottum left
right 通常情况下我们四选二即可实现定位</li>
</ul></li>
</ul>
<h2 id="绝对定位">5.2 绝对定位</h2>
<ul>
<li>当元素的position设置为abslute的时候开启了绝对定位</li>
<li>开启绝对定位之后不设置偏移量位置不会发生变化</li>
<li>开启绝对定位之后会从文档流脱离</li>
<li>绝对定位会改变元素的性质-&gt; 行内变快，块的大小被内容撑开</li>
<li>绝对定位会提升元素层级<br />
</li>
<li>绝对定位元素是相对于包含块进行定位的</li>
</ul>
<p>包含块：</p>
<ul>
<li><p>正常情况下：
包含块是当前元素最近的祖先元素<strong>块元素</strong></p>
<div>
<div>

</div>
</div></li>
<li><p>绝对定位的包含块 绝对定位的包含块就是离他最近的祖先元素
所有的祖先元素都没有开启定位就相对于根元素</p></li>
</ul>
<p><code>html</code>是根元素，也是初始包含块</p>
<p>于是有了一种对于确定大小的盒子的居中方式 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
<span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
<span class="token property">top</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token property">left</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token property">right</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token property">bottom</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token property">margin</span><span class="token punctuation">:</span> auto<span class="token punctuation">;</span></code></pre></p>
<h2 id="固定定位">5.3 固定定位</h2>
<p>将元素的posituin设置为fixed</p>
<ul>
<li>固定定位可以认为是一种特别的绝对定位</li>
<li>文档流脱离</li>
<li>改位置不动</li>
<li>内联变快，快内容撑开</li>
<li>唯一不同的是他们的参考系一定是视口</li>
</ul>
<h2 id="粘滞定位">5.4 粘滞定位</h2>
<ul>
<li>当元素的position属性设置为sticky则开启了元素的粘滞定位</li>
<li>粘滞定位和相对定位的特点基本一致，不同的是粘滞定位可以在元素达到某个位置时将其固定</li>
</ul>
<h2 id="水平垂直布局">5.5 水平垂直布局</h2>
<p>包含块的宽度=<span class="math inline">\(\Sigma\)</span>
7+绝对定位的left right</p>
<p>当发生过度约束的时候</p>
<ul>
<li>如果9个值没有auto就调整right</li>
<li>如果有auto就调整auto</li>
<li>left right的默认值是auto，所以如果不知道left right
而且等式不成立，那么自动调整这两个值</li>
</ul>
<p>垂直布局</p>
<ul>
<li><strong>top+margin<em>2+padding</em>2+height+buttom=h</strong></li>
</ul>
<h2 id="元素的垂直层级">5.6 元素的垂直层级</h2>
<p>对于开启了定位的元素，可以使用z-index指定元素的层级</p>
<ul>
<li>z-index需要一个整数作为参数,越大越优先显示</li>
<li>元素层级如果一样优先显示后面的</li>
<li>层级可以设置负数，但是别用</li>
<li>祖先元素的层级再高也不会盖住后代元素</li>
</ul>
<h1 id="表格与表单">6 表格与表单</h1>
<h2 id="表格">6.1 表格</h2>
<p>在现实生活中，我们经常需要使用表格表示格式化数据，课程表，名单，成绩单，在网页中我们也需要设置表格，通过使用table创建表格</p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span> <span class="token attr-name">border</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 在table中使用tr表示一行,有几个tr就表示几行 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span class="token punctuation">></span></span>
        <span class="token comment">&lt;!-- 在tr中使用td表示一个单元格,有几个td就是有几个单元格 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>tr</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span><span class="token punctuation">></span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>td</span> <span class="token attr-name">colspan</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>td</span><span class="token punctuation">></span></span>
        <span class="token comment">&lt;!-- 他会只占自己大小不合并单元格，除非指定 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>table</span><span class="token punctuation">></span></span></code></pre>
<h2 id="长表格">6.2 长表格</h2>
<p>可以将一个表格分为三部分</p>
<ul>
<li>表头 thead</li>
<li>主体 tbody</li>
<li>底部 tfoot</li>
<li>th 表格头部单元格</li>
</ul>
<h2 id="表格的样式">6.3 表格的样式</h2>
<ul>
<li>边框之间的间距 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">border-spacing</span><span class="token punctuation">:</span> 0px<span class="token punctuation">;</span></code></pre></li>
<li>边框合并 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">border-collapse</span><span class="token punctuation">:</span> collapse<span class="token punctuation">;</span></code></pre></li>
</ul>
<p><strong>如果不使用tbody直接使用tr，浏览器会自动创建一个tbody然后把所有tr放到里面，所以tr不是table子元素，这就导致子元素选择器无法选择</strong></p>
<ul>
<li>将元素设置为单元格 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">display</span><span class="token punctuation">:</span> table-cell<span class="token punctuation">;</span>
<span class="token property">vertical-align</span><span class="token punctuation">:</span> middle<span class="token punctuation">;</span></code></pre></li>
</ul>
<h2 id="表单">6.4 表单</h2>
<ul>
<li>现实生活中用于提交数据</li>
<li>网页中的表单用于将本地数据提交远程的服务器</li>
<li>使用form标签创建表单</li>
</ul>
<p>实例</p>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>form</span> <span class="token attr-name">action</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./target.html<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 添加表单项 --></span>
    <span class="token comment">&lt;!-- 文本框
        注意
            数据要提交的服务器中必须要指定一个name
    --></span>
    文本框<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>username<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    密码框<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>pw<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
    单选按钮
    <span class="token comment">&lt;!--必须有一个相同的name属性，否则不知道哪两个选项是一组的 --></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>radio<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hrll<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>a<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>radio<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hrll<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>b<span class="token punctuation">"</span></span> <span class="token attr-name">checked</span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>tt<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span> <span class="token attr-name">checked</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>tt<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span> <span class="token attr-name">checked</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>checkbox<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>tt<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>3<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>

    下拉列表
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>select</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>aa<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>option</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>i<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>选项一<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>option</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>option</span> <span class="token attr-name">selected</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ii<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>选项二<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>option</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>option</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>iii<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>选项三<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>option</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>select</span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- 提交按钮 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>注册<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>form</span><span class="token punctuation">></span></span></code></pre>
<h2 id="表单的属性">6.5 表单的属性</h2>
<ul>
<li>action 表单提交的地址 <pre class="language-html" data-language="html"><code class="language-html"><span class="token comment">&lt;!-- 关闭自动填充 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>form</span> <span class="token attr-name">action</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>./target.html<span class="token punctuation">"</span></span> <span class="token attr-name">autocomplete</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>on<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>username<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hello<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>color<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 自动获取焦点 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>email<span class="token punctuation">"</span></span> <span class="token attr-name">autofocus</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

    <span class="token comment">&lt;!-- 将表单设置为只读 数据提交 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fasd<span class="token punctuation">"</span></span> <span class="token attr-name">readonly</span><span class="token punctuation">></span></span>
    <span class="token comment">&lt;!-- 将表单设置为禁用 数据不提交 --></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fasd<span class="token punctuation">"</span></span> <span class="token attr-name">disabled</span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
    
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>reset<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>br</span><span class="token punctuation">></span></span>
    
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>button<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>按钮<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>form</span><span class="token punctuation">></span></span></code></pre></li>
</ul>
<h1 id="动画与过渡">7 动画与过渡</h1>
<h2 id="过渡">7.1过渡</h2>
<ul>
<li>通过过渡指定一个属性发生变化时候的切换方式</li>
<li>通过过渡效果可以创建一些非常好的效果提升用户体验</li>
</ul>
<p>过渡的简写属性是transition，还有很多属性</p>
<ol type="1">
<li>transition-property
指定要执行要被过渡的属性,多个属性之间’,‘隔开，所有属性都要过渡写all大部分属性都支持过渡效果，只要他的值是数值，可以计算的可以过渡注意过渡时必须是一个有效数值向另外一个过渡，例如auto就不是
<pre class="language-css" data-language="css"><code class="language-css"><span class="token property">transition-property</span><span class="token punctuation">:</span> width<span class="token punctuation">;</span></code></pre></li>
<li>transition-duration 指定过渡效果的持续时间，时间可以分别指定
<pre class="language-css" data-language="css"><code class="language-css"><span class="token property">transition-duration</span><span class="token punctuation">:</span> 1s</code></pre></li>
<li>transition-timing-function
过渡的时序函数，即过渡的执行方式，可选值：
<ul>
<li>ease 默认值 开始慢先加速后减速</li>
<li>linear 匀速直线</li>
<li>ease-in 加速运动</li>
<li>ease-out 减速运动</li>
<li>ease-in-out 先加速后减速<br />
速度实际上都是通过贝塞尔曲线指定的 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">transition-timing-function</span><span class="token punctuation">:</span> <span class="token function">cubic-bezier</span><span class="token punctuation">(</span>0<span class="token punctuation">,</span>0<span class="token punctuation">,</span>1<span class="token punctuation">,</span>1<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
四个值分别是贝塞尔曲线两个点的坐标</li>
<li>还可使用step 分步实现，transition-timing-function:
steps(3);，后面加end/start 表示是在这一阶段的开始还是结束执行</li>
</ul></li>
<li>transition-delay 等待一定的时间之后开始</li>
</ol>
<p>以上可以直接用transition，唯一的顺序要求是需要同时写持续和延迟，先持续后延迟</p>
<h2 id="动画">7.2 动画</h2>
<p>动画与过渡类似都可以实现动态的效果，不同的是过渡需要在某个属性发生变化的时候才会触发，<strong>动画是可以自动触发的效果</strong></p>
<p>设置动画效果必须先设置一个<strong>关键帧</strong>，关键帧设置了一个动画执行的每一个步骤</p>
<p>动画的属性设置全部是<strong>animation</strong>开头的:</p>
<ul>
<li>animation-name: 要对当前元素生效的关键帧的名字</li>
<li>animation-duration: 动画的持续时间</li>
<li>animation-timing-function :动画显示形式</li>
<li>animation-delay :动画的延时</li>
<li>animation-iteration-count:
动画迭代次数可以指定次数""无限执行infinite"</li>
<li>animation-direction: 动画执行的方向
<ul>
<li>normal 默认值 from到to运行每次都是这样</li>
<li>reverse 反向</li>
<li>alternate 当运行重复执行动画的时候偶数次反向执行</li>
</ul></li>
<li>animation-fill-mode: 动画执行结束的位置
正常情况下动画执行完毕之后并不会回到from的位置而是回到非动画的css样式
<ul>
<li>none 默认值 动画执行完毕之后回到原来的位置</li>
<li>forwards 动画执行完毕弧就地停下</li>
<li>backwords
在动画开始的等待期间元素就处于from关键帧状态否则不提前进入关键帧</li>
<li>both：结合了forwards和backwords</li>
</ul></li>
<li>animation-play-state: 动画的执行状态
<ul>
<li>running 默认值 运行</li>
<li>paused 动画暂停</li>
</ul></li>
</ul>
<p>以上全部使用animation一个实现，所以直接用且无顺序只要保证延时在后面写</p>
<p>实例 <pre class="language-CSS" data-language="CSS"><code class="language-CSS">&#x2F;* 动画的调用 *&#x2F;
.box1 .box2&#123;
    transition: all 2s;
    transition-timing-function: ease-out;
    animation: test 2s;
    animation-iteration-count: 4;
    animation-direction: alternate;
&#125;
&#x2F;* 动画的实现 *&#x2F;
@keyframes test &#123;
    &#x2F;* 指定动画的开始位置 from也可以写作0%*&#x2F;
    from&#123;
        margin-left: 0px;
    &#125;

    33.5%&#123;
        margin-left: 10px;
    &#125;

    &#x2F;* 指定动画的结束位置 to也可以写作100%*&#x2F;
    to&#123;
        margin-left: 7000px;
    &#125;
&#125;</code></pre></p>
<h2 id="变形">7.3 变形</h2>
<p>变形就是指通过CSS来改变元素的形状或者位置</p>
<ul>
<li>变形不会影响到元素的页面布局</li>
<li>transform 用来设置元素的变形效果
<ul>
<li><p>平移</p>
<ul>
<li>translateX() 沿着X轴平移</li>
<li>translateY() 沿着Y轴平移</li>
<li>translateZ() 沿着Z轴平移</li>
<li><strong>平移元素的百分比是相对于自身运算的</strong>
<pre class="language-CSS" data-language="CSS"><code class="language-CSS">transform: translateX(-100px);
transform: translateX(50%);</code></pre></li>
</ul></li>
<li><p>旋转：通过旋转可以是元素围绕xyz旋转指定角度</p>
<ul>
<li>transform: rotateX();</li>
<li>transform: rotateY();</li>
<li>transform: rotateZ();</li>
<li>backface-visibility: hidden; 是否显示元素的背面 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">rotateZ</span><span class="token punctuation">(</span>720deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span>.5turn<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">rotateY</span><span class="token punctuation">(</span>.5turn<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span>.5turn<span class="token punctuation">)</span> <span class="token function">rotateY</span><span class="token punctuation">(</span>.5turn<span class="token punctuation">)</span> <span class="token function">rotateZ</span><span class="token punctuation">(</span>.5turn<span class="token punctuation">)</span><span class="token punctuation">;</span> */
<span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">rotateY</span><span class="token punctuation">(</span>45deg<span class="token punctuation">)</span> <span class="token function">rotateZ</span><span class="token punctuation">(</span>50deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">/* 要把transform写在一起，但是有先后优先级 */</span>
<span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">rotateY</span><span class="token punctuation">(</span>180deg<span class="token punctuation">)</span> <span class="token function">translateZ</span><span class="token punctuation">(</span>400px<span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">/*Y轴是位置不变的*/</span>
<span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">translateZ</span><span class="token punctuation">(</span>400px<span class="token punctuation">)</span> <span class="token function">rotateY</span><span class="token punctuation">(</span>180deg<span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">/*Y轴是变化位置的*/</span></code></pre></li>
</ul></li>
<li><p>缩放</p>
<ul>
<li>scaleX()</li>
<li>scaleY()</li>
<li>还有z轴缩放，但是没有用，原因是scale的原理是将坐标轴拉长，不是直接放大图片</li>
<li>scale()同时缩放</li>
</ul></li>
<li><p>特殊的Z轴平移</p>
<p>Z轴平移就是在调整元素在Z轴的位置，正常情况下是调整元素和人眼之间的距离，距离越大元素离人越近</p>
<p>Z轴的平移属于立体效果(近大远小)默认情况下我们的网页时不支持透视的如果需要看到效果，必须设置网页的视距，设置方法为在html下写下(一般800-1200均可)
<pre class="language-css" data-language="css"><code class="language-css"><span class="token property">perspective</span><span class="token punctuation">:</span> 800px<span class="token punctuation">;</span></code></pre></p></li>
</ul></li>
</ul>
<h1 id="弹性容器与移动端">8 弹性容器与移动端</h1>
<h2 id="弹性盒伸缩盒子">8.1 弹性盒/伸缩盒子</h2>
<ul>
<li>是css的另一种布局手段，主要用来代替浮动完成页面的布局</li>
<li>如果你不需要兼容老浏览器就用flex要是需要兼容PC就用float</li>
<li>伸缩盒可以使元素更有弹性，让元素可以跟随页面的大小而改变</li>
<li>弹性容器
<ul>
<li>要使用弹性盒子必须先将元素设置为弹性容器</li>
<li>通过display设置弹性容器 display:flex 设置为块级元素的弹性盒子
display:inline-flex 设置为行内块元素的弹性盒子</li>
</ul></li>
<li>弹性元素
<ul>
<li>弹性容器的子元素是弹性元素(弹性项目)</li>
<li>只有弹性容器的直接子元素蚕食元素，后代元素不是</li>
<li>一个元素既可以是弹性容器也可以弹性元素</li>
</ul></li>
<li>弹性容器的属性
<ul>
<li>flex-direction 用于指定弹性元素的排列方式，可选值有
<ul>
<li>row
(默认值),弹性元素在容器中水平排列，这个row是按书写顺序排列，中国是左到右他就是左到右</li>
<li>row-reversw 反向水平排列</li>
<li>column 弹性元素纵向排列 (自上向下)</li>
</ul></li>
<li>主轴
<ul>
<li>弹性元素的排列方向称为主轴,例如row的时候主轴值自左向右...</li>
</ul></li>
<li>侧轴
<ul>
<li>与主轴垂直方向的称为侧轴 一般不说具体的方向只说水平还是垂直</li>
</ul></li>
</ul></li>
<li>弹性元素的属性
<ul>
<li>flex-grow 指定元素伸展的系数
<ul>
<li>当父元素有多余的空间的时候子元素如何伸展</li>
<li>父元素的剩余空间按比例分配</li>
</ul></li>
<li>flex-shrink 指定元素的收缩系数
<ul>
<li>当父元素中的空间不足以容纳所有的子元素时如何对子元素进行收缩</li>
<li>默认值是1 等比例收缩</li>
<li>0是不收缩</li>
<li>值越大收缩越多</li>
</ul></li>
</ul></li>
</ul>
<h2 id="弹性容器的使用">8.2 弹性容器的使用</h2>
<p>设置弹性元素是否在弹性容器中自动换行</p>
<ul>
<li>nowrap 元素不自动换行</li>
<li>wrap 元素自动换行</li>
<li>wrap-reverse 元素沿着辅轴反方向换行</li>
</ul>
<p>flex-flow wrap和direction 的简写属性</p>
<p>justify-content 如何分配主轴上的空白空间
主轴上的元素如何排列，可选值</p>
<ul>
<li>flex-start 沿着主轴起边排列 主轴较大值处空白</li>
<li>flex-end 元素沿着主轴终边排列</li>
<li>center 元素居中排列 空白分布到两边</li>
<li>space-around 空白分布到每一个元素的两侧
但是起始两个的左右是小一半</li>
<li>space-evenly 空白分布到元素单侧 所有的空隙全相等
(唯独这一个兼容性的不好)</li>
<li>space-between 空白分布元素之间，起始终止的左右没有</li>
</ul>
<p><strong>align 开头的是设置辅轴上的样式 </strong></p>
<p>alihn-items 是设置元素在辅轴上如何对齐</p>
<ul>
<li>他设置的是<strong>元素间</strong>的关系</li>
<li>stretch (默认值)将元素之间长度设置为相同值
这个行指的是与本行元素高度均相同，其他行不管</li>
<li>flex-start 元素不会拉伸沿着辅轴起边对齐</li>
<li>flex-end 辅轴终边对齐</li>
<li>center 居中对齐</li>
<li>baseline 基线对齐</li>
</ul>
<p>align-content 辅轴上的空白空间对齐方式，同justify-content</p>
<p>align-self 用来覆盖覆盖元素的align-items，相当于单独修改</p>
<h2 id="弹性元素的样式">8.3 弹性元素的样式</h2>
<p>弹性元素的增长系数<code>flex-grow</code>是分配是在宽度的基础上加上按比例分配的空白的空间</p>
<p>弹性元素的缩减系数<code>flex-shrink</code></p>
<ul>
<li>缩减系数的计算方式比较复杂</li>
<li>缩减多少是根据缩减系数和元素的大小来计算的</li>
</ul>
<p>计算元素<code>flex-basis</code>在主轴上的基础长度的时候就忽略了width，</p>
<ul>
<li>默认值是auto即参考元素自身的width</li>
<li>如果传递了一个具体的数字即以该值为准</li>
</ul>
<p><strong>可以理解为弹簧的三种状态</strong></p>
<ul>
<li>flex-basic就是弹簧自然状态</li>
<li>flex-grow 弹簧拉伸</li>
<li>flex-shrink 弹簧压缩</li>
<li>他们有一个通用属性 flex: grow shrink basic
<ul>
<li>flex有一个默认值 initial 相当于 flex:0 1 auto</li>
<li>flex有一个 auto 相当于 flex:1 1 auto</li>
<li>flex有一个 none 相当于 flex:0 0 auto 相当于弹性元素没有弹性</li>
</ul></li>
</ul>
<p>order 决定弹性元素的排列顺序</p>
<h2 id="像素与视口">8.4 像素与视口</h2>
<p>像素</p>
<ul>
<li>屏幕是由一个一个发光的小点构成的，这一个一个发光的小点就是一个一个像素</li>
<li>分辨率：1920*1080 说的就是屏幕中小点的数量</li>
<li>像素在前端开发中分成两种情况：CSS像素和物理像素</li>
<li>物理像素：上述所说的小点点就是物理像素</li>
<li>CSS像素：在编写网页的时候我们所用的像素就是css像素
<ul>
<li>浏览器在现实网页的时候需要把css像素转化为物理像素，然后再呈现</li>
<li>一个css像素最终由几个物理像素现实由浏览器决定，默认情况下PC端1个css像素就是1个物理像素</li>
</ul></li>
</ul>
<p>视口(viewport)</p>
<ul>
<li>视口就是屏幕中用来显示网页的区域</li>
<li>可以通过查看视口的大小来观察css像素和物理像素的比值</li>
<li>默认情况下视口的宽度就是html标签的宽度</li>
<li>浏览器放大两倍之后
<ul>
<li>视口宽度 960px 物理像素 1920px</li>
</ul></li>
<li>我们可以通过改变视口的大小改变比值</li>
</ul>
<h2 id="移动端介绍">8.5 移动端介绍</h2>
<p>在不同屏幕，单位像素的大小是不同的，像素越小，屏幕会越清晰</p>
<pre><code>https://material.io/resources/devices/</code></pre>
<p>智能手机的像素要远远小于计算机显示器的像素点，默认情况下移动端的网页都会被设置为980px(CSS像素)以确保PC端网页可以在移动端正常访问，但是如果网页的宽度超过980，移动端浏览器会自动对网页缩放以完整显示网页</p>
<p>所以基本上大部分PC端网站可以在移动端正常浏览器，但往往没有好的体验，为了解决这个问题大部分网站会专门为移动端设计网页</p>
<p>移动端默认的视口大小是980px(css像素)，默认情况下移动端的像素比是
980/移动端像素宽度，如果我们直接在网页端编写移动端代码，这样在980视口下我们的像素比是非常不友好的，导致网页中的内容非常非常小，编写移动端页面的时候必须要确保一个比较合理的像素比
<span class="math display">\[1CSS=2物理px\]</span></p>
<ul>
<li><p>我们可以改变视口的大小实现适配</p></li>
<li><p>可以通过meta设置视口的大小</p></li>
<li><p>每一款移动设备都会有最佳的像素比</p>
<ul>
<li>一般我们只要将像素比设置为该值就可以得到最佳像素比</li>
<li>视口将像素比设置为最佳像素比的视口大小成为完美视口</li>
</ul></li>
</ul>
<p>记住： <pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>viewport<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>width=device-width, initial-scale=1.0<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></code></pre></p>
<h2 id="视口">8.6 视口</h2>
<p>不同的设备完美视口的大小是不一样的</p>
<ul>
<li>iPhone6 -- 375</li>
<li>iPhone6Plus --414</li>
</ul>
<p>由于不同设备的视口和像素比不同，所以同样的375px在不同设备意义下是不一样的，例如在iPhone6中375是全屏的，但是在plus中375就会缺一个角，所以在移动端开发的时候就不能使用px来布局了，当然转而使用%就可以了，但是不能这样，应为网页复杂之后没法写了</p>
<h2 id="vm适配">8.7 vm适配</h2>
<p>vw是一个css的新单位，表示视口单位(viewport width)</p>
<ul>
<li>100vw就是一个视口的宽度</li>
<li>1vw就是1%视口宽度</li>
</ul>
<p>vw这个单位永远是相对于视口宽度进行计算，但是他在PC端适配并不好(移动端可以的)</p>
<p>当设计图的宽度为750px创建一个 48*35 的元素</p>
<ul>
<li>100vw = 750px</li>
<li>6.4vw = 48px</li>
<li>4.667vw = 35px</li>
</ul>
<p>但是这样实现涉及到计算，十分麻烦，可以使用rm进行适配</p>
<h2 id="响应式布局">8.8 响应式布局</h2>
<ul>
<li>网页课可以根据不同的设备窗口大小呈现不同的效果</li>
<li>使用响应式布局可以使一个网页适用于所有设备</li>
<li>响应式布局的关键是媒体查询</li>
<li>通过媒体查询可以为不同的设备或者不同的状态分别设置样式(屏幕 打印
屏幕阅读器)</li>
</ul>
<p>例如： <pre class="language-css" data-language="css"><code class="language-css"><span class="token atrule"><span class="token rule">@media</span> all</span> <span class="token punctuation">&#123;</span>
    <span class="token selector">body</span><span class="token punctuation">&#123;</span>
        <span class="token property">background-color</span><span class="token punctuation">:</span> #bfa<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
<span class="token atrule"><span class="token rule">@media</span> print</span><span class="token punctuation">&#123;</span>
    <span class="token selector">body</span><span class="token punctuation">&#123;</span>
        <span class="token property">background-color</span><span class="token punctuation">:</span> orange<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
<span class="token comment">/* 可以使用,表示并*/</span>
<span class="token atrule"><span class="token rule">@media</span> speech<span class="token punctuation">,</span>media</span> <span class="token punctuation">&#123;</span>
    <span class="token selector">body</span><span class="token punctuation">&#123;</span>
        <span class="token property">background-color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span></code></pre></p>
<p>在媒体类型前添加only 表示只有,only的使用时为了兼容老浏览器</p>
<h2 id="媒体特性">8.9 媒体特性</h2>
<ul>
<li>width 视口的宽度</li>
<li>height 视口的高度</li>
<li>min-width 视口的最小宽度 只要大于500就生效</li>
<li>max-width 视口的最大宽度</li>
</ul>
<p>样式切换的分界点我们也称为断点，也就是网页在这个时候发生变化</p>
<ul>
<li>小于 768 超小屏幕 max-width:768</li>
<li>大于 768 小屏幕 min-width:768</li>
<li>大于 992 中屏幕 min-width: 992</li>
<li>大于 1200 大屏幕 min-width: 1200</li>
</ul>
<h1 id="字体图标字体与渐变">9 字体,图标字体与渐变</h1>
<h2 id="字体">9.1 字体</h2>
<p>字体相关的样式</p>
<ul>
<li>color 用来设置字体颜色的</li>
<li>font-size 字体的大小，和font相关的单位
<ul>
<li>em 相当于当前元素的一个font-size</li>
<li>rem 相当于根元素的一个font-size</li>
</ul></li>
<li>font-family 字体族(字体)
<ul>
<li>可选值1：字体</li>
<li>可选值2：
<ul>
<li>serif 衬线字体</li>
<li>sans-serif 非衬线字体</li>
<li>monospace 等宽字体</li>
<li>注意：以上并不是字体，而是字体的分类，如果写了这三个只是告诉浏览器要用这类字体，具体用哪个浏览器自行决定</li>
</ul></li>
<li>我们往往可以指定很多值，用,隔开，字体名称有空格分号的要用''包起来</li>
</ul></li>
</ul>
<p><code>@font-face</code>
可以将服务器中的字体直接提供给用户去使用，但是存在问题问题： 1. 加载速度
2. 版权</p>
<h2 id="图标字体">8.2 图标字体</h2>
<p>在网页中经常使用到一些图标可以通过图片引入图标但是图片本身比较大，但是非常不灵活</p>
<ul>
<li>所以还可以将图标直接设定字体，然后通过fontface引入</li>
<li>这样就可以通过使用字体图标的形式来使用图标</li>
</ul>
<p>fontawsome 使用规范</p>
<ol type="1">
<li>官网下载</li>
<li>解压</li>
<li>将css和webfonts移到目录</li>
<li>将all.css引入网页</li>
<li>使用图标字体</li>
<li>直接通过类名来使用图标字体</li>
</ol>
<p>使用示例 <pre class="language-html" data-language="html"><code class="language-html"><span class="token comment">&lt;!-- 1. --></span>
li::before&#123;
    content: "\f1b0";
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;           /*fab需要单独设置*/
    color: blue;
    margin-right: 10px;     
&#125;

<span class="token comment">&lt;!-- 2. --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fas<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token entity" title="&#xf0f3;">&amp;#xf0f3;</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">></span></span>

<span class="token comment">&lt;!-- 3. --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>i</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fas fa-cat<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>i</span><span class="token punctuation">></span></span></code></pre></p>
<h2 id="字体的属性">8.3 字体的属性</h2>
<p>font: 可以设置字体相关的所有属性</p>
<p>写法一：先写字号在写字体 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">font</span><span class="token punctuation">:</span> 50px Cambria<span class="token punctuation">,</span> Cochin<span class="token punctuation">,</span> Georgia<span class="token punctuation">,</span> Times<span class="token punctuation">,</span> <span class="token string">'Times New Roman'</span><span class="token punctuation">,</span> serif<span class="token punctuation">;</span></code></pre> 写法二：字号/行高在写字体
<pre class="language-css" data-language="css"><code class="language-css"><span class="token property">font</span><span class="token punctuation">:</span> 50px/5 Cambria<span class="token punctuation">,</span> Cochin<span class="token punctuation">,</span> Georgia<span class="token punctuation">,</span> Times<span class="token punctuation">,</span> <span class="token string">'Times New Roman'</span><span class="token punctuation">,</span> serif<span class="token punctuation">;</span></code></pre> 省略不是不写是用了默认值</p>
<p>font-weight: 字重</p>
<ul>
<li>normal 不加粗</li>
<li>bold 加测</li>
<li>100-900
表示9个加粗的级别,虽然提供了9个级别，但是没什么用,因为电脑上不可能安装这么多字重字体</li>
</ul>
<h2 id="文本样式">8.4 文本样式</h2>
<p>text-align 文本水平对齐</p>
<ul>
<li>left默认值</li>
<li>right 右对齐</li>
<li>center 居中对齐</li>
<li>justify 两端对齐</li>
</ul>
<p>vertical-align 垂直 对齐</p>
<ul>
<li>baseline 基线对齐 默认</li>
<li>top 顶部对齐，父子顶部对齐</li>
<li>bottom 底部对齐</li>
<li>middle 居中对齐 一般不用</li>
<li>指定数值调整位置</li>
</ul>
<p>text-decoration 设置文本修饰</p>
<ul>
<li>none 默认值 什么也没有</li>
<li>underline 下划线</li>
<li>overline 上划线</li>
<li>linethrough 穿过的线 后面还可以加颜色，给线改色 但是IE不支持</li>
</ul>
<h2 id="背景">8.5 背景</h2>
<ul>
<li>background-color 设置背景颜色</li>
<li>background-image 设置背景图片
<ul>
<li>可以同时设置背景图片的颜色，这样背景颜色将会成为图片的背景</li>
<li>如果背景图片小于元素，则背景图片会在元素中平铺将元素铺满</li>
<li>如果背景图片大于元素 将会有一部分图片无法显示</li>
<li>如果两者一样大则会正常显示</li>
</ul></li>
<li>background-repeat
<ul>
<li>repeat 默认值，背景会沿着xy轴双方向重复</li>
<li>repeat-x 沿着x轴方向重复</li>
<li>repeat-y 沿着y轴方向重复</li>
<li>no-repeat 不重复</li>
</ul></li>
<li>background-position 用来这只背景图片的位置
<ul>
<li>通过left...设置图片的位置 例如background-position: left
center,使用方位词的时要写两个，如果写一个的话，默认第二个是center</li>
<li>通过偏移量指定图片的位置 水平和垂直</li>
</ul></li>
<li>background-clip
<ul>
<li>border-box 默认值 背景会出现边框下面</li>
<li>padding-box 背景不会出现在边框只出现在内容区和内边距</li>
<li>content-box 背景只出现在内容区</li>
</ul></li>
<li>background-origin 背景图片偏移量计算原点
<ul>
<li>padding-box 默认值 background-position 从内边距开始计算</li>
<li>content-box background-position 从内容区开始计算</li>
<li>border-box background-position 从边框开始计算</li>
</ul></li>
<li>background-size 设置背景图片的大小
<ul>
<li>第一个值表示宽度</li>
<li>第二个值表示高度</li>
<li>如果指定一个值，另一个值就是auto，等比例缩放</li>
<li>cover 比例不变，将元素铺满</li>
<li>content 比例不变 图片完整显示</li>
</ul></li>
<li>background-attachment 背景图片是否跟随元素滚动
<ul>
<li>scroll 背景图片跟随元素移动</li>
<li>fixed 背景图片会固定在页面中</li>
</ul></li>
</ul>
<p>background 所有上述相关属性都可以设置 没顺序
但是origin在clip前面,background-size和background-positiom顺序为size/position
没有size不能写position</p>
<h2 id="渐变">8.6 渐变</h2>
<p>通过设置渐变可以实现很多复杂的背景颜色可以从一个颜色向另一个颜色变化</p>
<p><strong>渐变是图片，通过background-image设置</strong></p>
<p><strong>线性渐变</strong>，颜色沿着直线变化 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">linear-gradient</span><span class="token punctuation">(</span>red<span class="token punctuation">,</span>yellow<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
红色在开头，黄色在结尾 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">linear-gradient</span><span class="token punctuation">(</span>to right<span class="token punctuation">,</span>red<span class="token punctuation">,</span>yellow<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> 前面加to指定渐变的方向
<pre class="language-css" data-language="css"><code class="language-css"><span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">linear-gradient</span><span class="token punctuation">(</span>45deg<span class="token punctuation">,</span>red<span class="token punctuation">,</span>yellow<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> 直接指定旋转度数 例如 25deg 0.2turn(0.25圈)</p>
<p>渐变可以指定多种颜色，每种颜色默认情况下平均分配 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">linear-gradient</span><span class="token punctuation">(</span>45deg<span class="token punctuation">,</span>red 50px<span class="token punctuation">,</span>yellow<span class="token punctuation">,</span>#bfa<span class="token punctuation">,</span>orange<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
表示红色是c从50px开始，之前的就是纯红色</p>
<p><strong>径向渐变</strong>: radial-gradient
默认情况下径向渐变的形状是根据元素形状变化的</p>
<ul>
<li>正方形-&gt;圆</li>
<li>长方形-&gt;椭圆形</li>
<li>可以手动指定圆心的大小与位置 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">radial-gradient</span><span class="token punctuation">(</span>100px 100px<span class="token punctuation">,</span>red<span class="token punctuation">,</span>yellow<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">radial-gradient</span><span class="token punctuation">(</span>100px 100px at 0 0<span class="token punctuation">,</span>red<span class="token punctuation">,</span>yellow<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></li>
<li>可以这只重复 <pre class="language-css" data-language="css"><code class="language-css"><span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token function">repeating-radial-gradient</span><span class="token punctuation">(</span>100px 100px<span class="token punctuation">,</span>red<span class="token punctuation">,</span>yellow<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></li>
</ul>

    </div>

    
    
    
      


    <footer class="post-footer">
          <div class="reward-container">
  <div></div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.png" alt="Liu Kairui 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.png" alt="Liu Kairui 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Liu Kairui
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://liukairui.me/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" title="HTML&amp;CSS学习笔记">http://liukairui.me/article/HTML&CSS学习笔记/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag"><i class="fa fa-tag"></i> 前端</a>
              <a href="/tags/%E7%AC%94%E8%AE%B0/" rel="tag"><i class="fa fa-tag"></i> 笔记</a>
              <a href="/tags/CSS/" rel="tag"><i class="fa fa-tag"></i> CSS</a>
              <a href="/tags/HTML/" rel="tag"><i class="fa fa-tag"></i> HTML</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/article/Less%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" rel="prev" title="Less学习笔记">
                  <i class="fa fa-chevron-left"></i> Less学习笔记
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/article/BootStrap%E7%AC%94%E8%AE%B0/" rel="next" title="BootStrap 笔记">
                  BootStrap 笔记 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="valine-comments"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2019 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Liu Kairui</span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>
  <div class="addthis_inline_share_toolbox">
    <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-6231eb6f709fc868" async="async"></script>
  </div><script
  async
  src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"
></script>

 
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment-precise-range-plugin@1.3.0/moment-precise-range.min.js"></script>
<script>
  function timer() {
    var ages = moment.preciseDiff(moment(),moment(20201101,"YYYYMMDD"));
    ages = ages.replace(/years?/, "年");
    ages = ages.replace(/months?/, "月");
    ages = ages.replace(/days?/, "天");
    ages = ages.replace(/hours?/, "小时");
    ages = ages.replace(/minutes?/, "分");
    ages = ages.replace(/seconds?/, "秒");
    ages = ages.replace(/\d+/g, '<span class="daysCnt" style="color:#1890ff">$&</span>');
    div.innerHTML = `我已在此等候你 ${ages}`;
    div.className="workDays";
  }
  var div = document.createElement("div");
  //插入到copyright之后
  var copyright = document.querySelector(".copyright");
  document.querySelector(".footer-inner").insertBefore(div, copyright.nextSibling);
  timer();
  setInterval("timer()",1000)
</script>



    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js" integrity="sha256-yt2kYMy0w8AbtF89WXb2P1rfjcP/HTHLT7097U8Y5b8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.7/pangu.min.js"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  
<script src="https://cdn.jsdelivr.net/npm/hexo-generator-searchdb@1.4.0/dist/search.js" integrity="sha256-vXZMYLEqsROAXkEw93GGIvaB2ab+QW6w3+1ahD9nXXA=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>


  <script class="next-config" data-name="mermaid" type="application/json">{"enable":true,"theme":"forest","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.14.0/mermaid.min.js","integrity":"sha256-7wT34TI0pEBeEFoi4z+vhuSddGh6vUTMWdqJ2SDe2jg="}}</script>
  <script src="/js/third-party/tags/mermaid.js"></script>

  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>

  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


  <script class="next-config" data-name="leancloud_visitors" type="application/json">{"enable":true,"app_id":"ABKlVtS4cyaWYEwunPyK3sXt-9Nh9j0Va","app_key":"xxGXdTTEGEVifs2TLB35844I","server_url":"https://abklvts4.lc-cn-e1-shared.com","security":false}</script>
  <script src="/js/third-party/statistics/lean-analytics.js"></script>


  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","mhchem":true,"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.min.js"}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


  <script src="https://cdnjs.cloudflare.com/ajax/libs/quicklink/2.2.0/quicklink.umd.js" integrity="sha256-4kQf9z5ntdQrzsBC3YSHnEz02Z9C1UeW/E9OgnvlzSY=" crossorigin="anonymous"></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":false,"archive":false,"delay":true,"timeout":3000,"priority":true,"url":"http://liukairui.me/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"}</script>
  <script src="/js/third-party/quicklink.js"></script>
<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>

<script>
var options = {
  bottom: '64px',
  right: 'unset',
  left: '32px',
  time: '0.5s',
  mixColor: 'transparent',
  backgroundColor: 'transparent',
  buttonColorDark: '#100f2c',
  buttonColorLight: '#fff',
  saveInCookies: true,
  label: '🌓',
  autoMatchOsTheme: true
}
const darkmode = new Darkmode(options);
window.darkmode = darkmode;
darkmode.showWidget();
</script>


<script class="next-config" data-name="valine" type="application/json">{"enable":true,"appId":"ABKlVtS4cyaWYEwunPyK3sXt-9Nh9j0Va","appKey":"xxGXdTTEGEVifs2TLB35844I","serverURLs":"https://abklvts4.lc-cn-e1-shared.com","placeholder":"请开始你的表演","avatar":"identicon","meta":["nick","mail","link"],"pageSize":10,"lang":"zh-CN","visitor":false,"comment_count":true,"recordIP":true,"enableQQ":true,"requiredFields":[],"el":"#valine-comments","path":"/article/HTML&CSS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"}</script>
<script>
document.addEventListener('page:loaded', () => {
  NexT.utils.loadComments(CONFIG.valine.el)
    .then(() => NexT.utils.getScript(
      'https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js',
      { condition: window.Valine }
    ))
    .then(() => {
      new Valine(CONFIG.valine);
    });
});
</script>


  <script async src="/js/fireworks.js"></script>




  <script src="/js/activate-power-mode.min.js"></script>
  <script>
    POWERMODE.colorful = true;
    POWERMODE.shake = false;
    document.body.addEventListener('input', POWERMODE);
  </script>




  <script src="/js/wobblewindow.js"></script>
  <script>
    //只在桌面版网页启用特效 记得同步到header.njk
    if( window.innerWidth > 768  ){
      $(document).ready(function () {
        
          $('body>main>header').wobbleWindow({
            radius: 50,
            movementTop: false,
            movementLeft: false,
            movementRight: false,
            debug: false,
          });
        

        //
        //  $('body header>aside').wobbleWindow({
        //    radius: 50,
        //    movementLeft: false,
        //    movementTop: false,
        //    movementBottom: false,
        //    position: 'fixed',
        //    debug: false,
        //  });
        //

        
          $('body>footer').wobbleWindow({
            radius: 50,
            movementBottom: false,
            movementLeft: false,
            movementRight: false,
            debug: false,
          });
        
      });
    }
  </script>


 
<script>
  $(document).ready(function(){
    var beian = document.querySelector(".footer-inner > .beian > a");
    var cpr=document.querySelector(".footer-inner > .copyright");
    var cnz=document.querySelector(".workDays");//.parentNode;
    var bsz=document.querySelector(".busuanzi-count");
    if(cnz!=null&&bsz!=null)
      cnz.parentNode.insertBefore(bsz,cnz);
    if(bsz == null || bsz == undefined || document.querySelector("#busuanzi_value_site_pv").innerText=="" || document.querySelector("#busuanzi_value_site_uv").innerText == "")
      bsz.remove();
    checkIndex();
    if(beian){cpr.classList.add('split-line');cpr.appendChild(beian);}
  })
  $(document).on('pjax:complete',checkIndex);
</script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false},"react":{"opacity":0.7}});</script></body>
</html>
